using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace KeyAuthService.Dialogs
{
    /// <summary>
    /// 现代风格文本详情窗口
    /// </summary>
    public class ModernTextDetailsWindow : Window
    {
        public ModernTextDetailsWindow(string title, string content)
        {
            Title = title;
            Style = (Style)FindResource("DialogWindowStyle");
            Width = 600;
            Height = 500;
            MinWidth = 500;
            MinHeight = 300;
            ResizeMode = ResizeMode.CanResize;
            WindowStartupLocation = WindowStartupLocation.CenterScreen;
            Topmost = true;
            ShowInTaskbar = false;
            
            // 创建主容器
            var grid = new Grid();
            grid.Style = (Style)FindResource("DialogContainerStyle");
            
            grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
            grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
            grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
            
            // 标题文本
            var titleText = new TextBlock
            {
                Text = "详细信息",
                Style = (Style)FindResource("DialogTitleStyle")
            };
            
            // 详情文本框
            var textBox = new TextBox
            {
                Style = (Style)FindResource("DialogTextDetailsStyle"),
                Text = content,
                IsReadOnly = true,
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch
            };
            
            // 按钮面板
            var buttonPanel = new StackPanel
            {
                Style = (Style)FindResource("DialogButtonPanelStyle")
            };
            
            // 复制按钮
            var btnCopy = new Button
            {
                Content = "复制内容",
                Style = (Style)FindResource("DialogSecondaryButtonStyle")
            };
            
            // 关闭按钮
            var btnClose = new Button
            {
                Content = "关闭",
                Style = (Style)FindResource("DialogPrimaryButtonStyle"),
                IsDefault = true,
                IsCancel = true
            };
            
            btnCopy.Click += (s, e) => 
            {
                try
                {
                    Clipboard.SetText(content);
                    // 显示复制成功的提示
                    var copyMsg = new TextBlock
                    {
                        Text = "✓ 已复制到剪贴板",
                        Foreground = new SolidColorBrush(Color.FromRgb(76, 195, 138)),
                        HorizontalAlignment = HorizontalAlignment.Left,
                        Margin = new Thickness(0, 0, 10, 0),
                        VerticalAlignment = VerticalAlignment.Center
                    };
                    buttonPanel.Children.Insert(0, copyMsg);
                    
                    // 2秒后移除提示
                    var timer = new System.Windows.Threading.DispatcherTimer
                    {
                        Interval = TimeSpan.FromSeconds(2)
                    };
                    timer.Tick += (sender, args) =>
                    {
                        buttonPanel.Children.Remove(copyMsg);
                        timer.Stop();
                    };
                    timer.Start();
                }
                catch (Exception) { }
            };
            btnClose.Click += (s, e) => Close();
            
            // 添加按钮到面板
            buttonPanel.Children.Add(btnCopy);
            buttonPanel.Children.Add(btnClose);
            
            // 添加控件到布局
            grid.Children.Add(titleText);
            Grid.SetRow(titleText, 0);
            
            grid.Children.Add(textBox);
            Grid.SetRow(textBox, 1);
            
            grid.Children.Add(buttonPanel);
            Grid.SetRow(buttonPanel, 2);
            
            Content = grid;
        }
    }
} 